package com.stu.chart.config;

import com.stu.chart.entity.Staff;
import com.stu.chart.service.ChartContentService;
import com.stu.chart.service.StaffService;
import com.stu.chart.service.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author dsj
 */
@Configuration
public class MyPicConfig implements WebMvcConfigurer {
    @Value("${file.temp}")
    private String filePath;
    @Autowired
    private WebSocketServer webSocketServer;
    @Autowired
    private StaffService staffService;
    @Autowired
    private ChartContentService chartContentService;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String os = System.getProperty("os.name");
        if (os.toLowerCase().startsWith("win")) { // windos系统
            registry.addResourceHandler("/file/**")
                    .addResourceLocations("file:" + filePath + "\\");
        } else { // MAC、Linux系统
            registry.addResourceHandler("/file/**")
                    .addResourceLocations("file:" +filePath + "/");
        }
        webSocketServer.init(staffService,chartContentService);
    }
}
